package com.cc.config.security;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cc.entity.Employees;
import com.cc.entity.LoginUser;
import com.cc.mapper.EmployeesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @ClassName: UserDetailsServiceImpl
 * @Description:
 * @Author: 晓东√
 * @Date: 2024-12-16 15:22
 * @Version: 1.0
 **/
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    EmployeesMapper employeesMapper;
    @Override
    public LoginUser loadUserByUsername(String username){

        LambdaQueryWrapper<Employees> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Employees::getLoginName,username);

        Employees employees = employeesMapper.selectOne(queryWrapper);
        if (employees == null) {
            throw new UsernameNotFoundException("用户不存在");
        }
        //todo 获取用户权限
        return new LoginUser(employees,null);
    }
}
